import {
  BaseScene
} from "../object/baseScene";
import {
  ChessBoard
} from "../object/chessBoard";

export class PracticeScene extends BaseScene {
  constructor() {
    super('PracticeScene')
  }
  init() {
    this.cameras.main.setBackgroundColor(0xcfe4f5)
    this.status = 0 // 游戏状态 0正在进行 1结束

    this.backText = this.add.text(this.gameWidth - 100, 30, '返回', {
      fontSize: 28,
      fontFamily: '楷体',
      color: '#000000'
    })
    this.backText.setInteractive()
    this.backText.on('pointerdown', () => {
      this.scene.switch('LoadScene')
    })


    this.textStyle = {
      fontSize: 32,
      fontFamily: '楷体',
      color: '#000000'
    }

    this.codeText = this.add.text(30, 30, '黑方步棋...', this.textStyle)
  }
  // 绘制棋盘
  _drawCheck() {
    this.chessBoard = new ChessBoard(this)
    this.chessBoard.draw()
  }
  // 第一子不在正中天元
  firstBlackCheck() {
    this.game.Vue.$message.warning('第一黑子必须在正中天元位置')
  }
  // 一方胜利
  Victory() {
    this.status = 1
    let text = (this.chessBoard.player == 1 ? '黑子方' : '白子方') + '胜出'
    this.codeText.setText(text)
    // this.game.Vue.$message.success(text)
    this.game.Vue.notify(text)
  }
  // 重开
  reset() {
    this.chessBoard.reset()
    this.status = 0
    this.codeText.setText('黑方步棋...')
  }
  // 是否允许布棋
  isAllowCheck() {
    return this.status == 0
  }
  // 布棋之后
  chessAfter() {
    let text = (this.chessBoard.player == 1 ? '黑' : '白') + '方步棋...'
    this.codeText.setText(text)
  }
  preload() {}
  create() {
    this._drawCheck()
    this.resetText = this.add.text(
      this.computedX(-this.chessBoard.checkBg.width / 2),
      this.computedY(-this.chessBoard.checkBg.height - 30),
      '重置', this.textStyle
    )
    this.resetText.setInteractive()
    this.resetText.on('pointerdown', this.reset, this)

    this.markText = this.add.text(
      this.computedX(this.chessBoard.checkBg.width),
      this.computedY(-this.chessBoard.checkBg.height - 30),
      '棋步', this.textStyle
    )
    this.markText.setInteractive()
    this.markText.on('pointerdown',()=>{
      this.chessBoard.showMark()
    })
    // this.chessBoard.showMark()
  }
  update() {

  }
}
